package cc.leap.web.monitor;

import cc.leap.model.AjaxResult;
import cc.leap.model.TableDataInfo;
import cc.leap.model.domain.SysJob;
import cc.leap.service.SysJobService;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.java.Log;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Put;
import org.quartz.SchedulerException;

/**
 * SysJobController
 *
 * @author leap
 * @date 2024/8/21
 */
@Controller
@Mapping("/monitor/job")
public class SysJobController {

    @Inject
    SysJobService jobService;

    /**
     * 查询定时任务列表
     */
    @SaCheckPermission("monitor:job:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<SysJob> list(SysJob sysJob) {
        return jobService.selectJobPage(sysJob);
    }

    /**
     * 定时任务立即执行一次
     */
    @SaCheckPermission("monitor:job:changeStatus")
    @Put
    @Mapping("/run")
    public AjaxResult run(SysJob job) throws SchedulerException {
        boolean result = jobService.run(job);
        return result ? AjaxResult.success() : AjaxResult.error("任务不存在或已过期！");
    }
}
